﻿@using PMP.Models.ViewModel;
@{
    ViewBag.Title = "考试管理";
    Exam exam = ViewBag.exam;
    List<Quest> listq = ViewBag.listq;
    List<ExamQuestRel> listr = ViewBag.listr;
}
<style>
    #tab1 th, #tab1 td {
        text-align: center;
    }

        #tab1 td.left {
            text-align: left;
        }

        #tab1 td.right {
            text-align: right;
        }
</style>

<div>
    <a href="@Url.Action("Manager")" class="layui-btn">返回考试管理</a>
</div>
<div>
    @exam.Name
</div>
<div>
    <a class="layui-btn" href="@Url.Action("RelAdd",new { ID=exam.ID})">添加题目</a>
    <a class="layui-btn" href="@Url.Action("RelDel",new { ID=exam.ID})">移除</a>
</div>
<table id="tab1" class="layui-table">
    <thead>
        <tr>
            <th width="10%">序号</th>
            <th width="10%">ID</th>
            <th>题目</th>
            <th width="20%">操作</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>


<div id="divtxt" style="display:none;">
    <div class="layui-form" style="margin:1em; padding:1em; ">
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">题目ID</label>
            <div class="layui-input-block">
                <textarea id="txtArea" placeholder="请输入题目ID，每个ID一行" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="btnok" onclick="ok();"><i class="layui-icon layui-icon-ok"></i>确定</button>
                <button class="layui-btn" id="btncancel"><i class="layui-icon layui-icon-close"></i>取消</button>
            </div>
        </div>
    </div>
</div>
@section script{
    <script>
        $(document).ready(function () {
            reload();
        });


        function add() {
            let winw = window.innerWidth * 0.6;
            let winh = window.innerHeight * 0.6;
            $("#txtArea").css("height", (winh - 120) + "px");
            let index = layer.open({
                type: 1,
                area: [winw + 'px', winh + 'px'],
                shade: false,
                title: false, //不显示标题
                content: $('#divtxt')
            });
            $("#btncancel").click(function () {
                layer.close(index);
            });
        }
        function ok() {
            let text = $("#txtArea").val();
            let arr = text.split("\n");

            let obj = new Object();
            obj.eid = @exam.ID;
            obj.ids = arr.join(",");
            layer.msg("正在保存，请稍候...", {
                icon: 16,
                time: 0,
                shade: 0.3,
                shadeClose: false
            });
			$.ajax({
				type: "POST",
				url: "@Url.Action("AddRel",new { EID=exam.ID})",
				data: obj,
                success: function (result) {
					layer.msg(result.msg);
				},
				error: function (err) {
					layer.msg(err.responseText);
				}
            });
            //$('#btncancel').click();
        }

        function reload() {
            $.ajax({
				type: "POST",
				url: "@Url.Action("RelList",new { EID=exam.ID})",
				data: obj,
                success: function (html) {
                    $("#divtab").html(html);
				},
				error: function (err) {
					layer.msg(err.responseText);
				}
            });
        }

        function remove(ele) {
            let tr = $(ele).parent().parent();
            let obj = new Object();
            obj.ID = tr.attr("rid");
            obj.EID = tr.attr("eid");
            obj.QID = tr.attr("qid");
            layer.msg("正在保存，请稍候...", {
                icon: 16,
                time: 0,
                shade: 0.3,
                shadeClose: false
            });
            $.ajax({
                type: "POST",
                url: "@Url.Action("RemoveRel")",
                data: obj,
                success: function (result) {
                    tr.remove();
                    layer.msg(result.msg);
                },
                error: function (err) {
                    layer.msg(err.responseText);
                }
            });
        }
    </script>
}
